package com.example.huangbei.dispatcher;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.dispatcher.DispatchFactory;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button jump_btn;
    private DispatchFactory dispather;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        jump_btn = (Button)findViewById(R.id.jump_btn);
        jump_btn.setOnClickListener(this);
        try {
            dispather = DispatchFactory.getInstance();
            dispather.init(getAssets().open("jump.xml"));
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onClick(View view) {
        if(view == jump_btn){
            Bundle bundle = new Bundle();
            bundle.putString("parameter01","p1");
            bundle.putString("parameter02","p2");
            bundle.putString("parameter03","p3");
           dispather.jump(this,"test02",bundle);
            //dispather.jumpForResult(this,"test02",bundle,1);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String str = "requestCode = "+requestCode+",resultCode = "+resultCode;
        Toast.makeText(this,str,Toast.LENGTH_SHORT).show();
    }
}
